package com.njust.service;

import com.njust.dao.EmployeeDao;
import com.njust.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {

    @Autowired
    EmployeeDao employeeDao;

    /**
     * 添加员工
     * @param employee
     */
    public boolean saveEmployee(Employee employee){
        Employee e = getEmployee(employee.getId());
        if (e != null){
            return employeeDao.updateEmployee(employee);
        }
       return  employeeDao.saveEmployee(employee);
    }

    /**
     * 删除员工
     */
    public boolean deleteEmployee(int id){
        return employeeDao.deleteEmployee(id);
    }
    /**
     * 更新员工
     */
    public boolean updateEmployee(Employee employee){
        return employeeDao.updateEmployee(employee);
    }

    public List<Employee> getAllEmployee(){
        return employeeDao.getAllEmployee();
    }

    /**
     * @param id
     * @return
     */
    public Employee getEmployee(int id){
        return employeeDao.getEmployeeById(id);
    }
}
